var/list/allowed_types = list(/obj/gettable/stackable/consumable, /skill, /obj/hud/selectable)
var/list/allowed_creative = allowed_types + typesof(/obj/hud/building)


#define MAX_HUD 10

obj/hud
	layer=MOB_LAYER+5
	icon='base.dmi'

	selectable
		icon_state="hud"
		var/slot=0
		var/skill/skillref
		mouse_opacity = 2
		New(loc, num)
			..()
			slot = num
			screen_loc = "1,[num+1]"

		proc/handle_skill(mob/caller, skill/s)
			if(skillref || !s) return 0
			skillref = s
			skillref.screen_loc = screen_loc
			caller.client.screen += skillref
			return 1

		MouseDrag()
			if(skillref)
				usr.client.mouse_pointer_icon = new /icon(skillref.icon, skillref.icon_state)

		MouseDrop(src_object,over_object,src_location,over_location,src_control,over_control,params)
			usr.client.mouse_pointer_icon = null
			if(istype(src_object, /obj/hud/selectable))
				var/obj/hud/selectable/s = src_object
				if(!skillref)return
				if(s.handle_skill(skillref.caster, skillref))
					skillref=null
			else
				usr.client.screen -= skillref
				skillref=null

		LeftClick(mob/caller)
			if(skillref)
				skillref.cast(caller)


mob/player/proc
	create_hud()
		//TODO select query
		for(var/x=1 to MAX_HUD)
			client.screen += new /obj/hud/selectable(null,x,src)

	clear_hud()
		if(isbuildable(loc))
			for(var/obj/o in client.screen)
				if(!(o.type in allowed_creative))
					client.screen -= o
		else
			for(var/obj/o in client.screen)
				if(!(o.type in allowed_types))
					client.screen -= o
